package com.runfast.paotui.restdocs;

import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.Claim;
import com.runfast.common.utils.TokenUtil1;
import com.runfast.paotui.dao.model.RunfastLoginRecord;
import com.runfast.paotui.dao.model.RunfastShopper;
import com.runfast.paotui.service.RunfastLoginRecordService;
import com.runfast.paotui.service.RunfastShopperService;
import com.runfast.waimai.util.AESUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import java.sql.SQLOutput;
import java.util.Date;
import java.util.StringTokenizer;

@SpringBootTest
@RunWith(SpringRunner.class)
public class tokentest {
    @Resource
    RunfastShopperService shopperService;
    @Resource
    RunfastLoginRecordService runfastLoginRecordService;
    RunfastLoginRecord runfastLoginRecord=new RunfastLoginRecord();
    String token="abc";
    @Test
    public void te(){

        RunfastShopper shopper=shopperService.get(1);
        String[] returnString = null;
        int i=0;
        if(shopper!=null){

            StringTokenizer tempString = new StringTokenizer("a", token);
            returnString = new String[tempString.countTokens()];
            while(tempString.hasMoreTokens())
            {
                returnString[i++] = tempString.nextToken();
            }

       //     return returnString;
            System.out.println( returnString);
           shopper.setToken(returnString.toString().trim());

         //   shopperService.addtoken(shopper);
            System.out.println(shopper.getToken()+"测试");

        }
    }
    @Test
 public  void isAccessAllowed(){//ServletRequest request, ServletResponse response, Object mappedValue
   //     HttpServletRequest httpServletRequest = (HttpServletRequest) request;
      //  String token = httpServletRequest.getHeader(TokenUtil1.TOKEN);
        String s = "{\r\n" +
                "    \"token\": \"ce13ea00-611e-42f7-aaf8-8bfefd025824\",\r\n" +
                "    \"orderId\": \"f797c69b698d11e8852f801844e735c4\"\r\n" +
                "}";
        String a="张三";
        String b="abcd";
       String c= AESUtil.encrypt(a,"abcdefgabcdefg12");

//            JWT decode = JWT.decode(token);
//           Claim claim = decode.getClaim(TokenUtil1.SHOPPER_ID);
//            Integer shopperId = claim.asInt();
                RunfastShopper shopper=shopperService.get(3);

            shopper.setToken(c);
            shopperService.addtoken(shopper);
                 System.out.println(c);
          String s1=  AESUtil.decrypt(c,"abcdefgabcdefg12");
        System.out.println(s1);
    }
    @Test
    public void aaa(){

        runfastLoginRecord.setAlias("40");
        runfastLoginRecord.setLogintime(new Date());
        runfastLoginRecord.setAccounttype(2);
        runfastLoginRecord.setAccountid(110115);
        runfastLoginRecordService.insertSelective(runfastLoginRecord);
        System.out.println(runfastLoginRecord.getId()+"能不能显示Id");
        System.out.println( runfastLoginRecordService.getshopperLoginmsg(runfastLoginRecord.getAccountid()).getId()+"看看Id");

    }
    @Test
    public void aaa1(){
        System.out.println(runfastLoginRecordService.findid(1419));
    //    runfastLoginRecord.getId()=1419;
       RunfastLoginRecord runfastLoginRecord1= runfastLoginRecordService.findid(1422);
        runfastLoginRecord1 .setLogouttime(new Date());
        runfastLoginRecordService.updateByPrimaryKeySelective(runfastLoginRecord1);
        System.out.println(runfastLoginRecordService.findid(1422)+"更新后");

    }
}
